﻿using UnityEngine;
using System.Collections;
using DG.Tweening;

public class Blink : promptSkill
{
    public Blink(Actor master) : base(master)
    {
        skillname = "闪现";
        armatureName = null;
        beforeCast = 0.0f;
        afterCast = 0.4f;
        canStop = false;
    }

    private void BlinkShow()
    {
        var FollowTarget = master.transform;
        foreach (UnityEngine.Transform item in FollowTarget)
        {
            var go = GameObject.Instantiate(item.gameObject, item.position, item.rotation) as GameObject;
            go.transform.localScale = FollowTarget.transform.localScale;
            go.AddComponent<AfterImageTransparent>();
        }
    }

    public override void work()
    {
        Vector2 vv = new Vector2(master.transform.position.x, master.transform.position.y) +
            new Vector2(master.transform.right.x, master.transform.right.y) * -3 * master.transform.localScale.x;
        DOTween.To(() => {
            return (Vector2)master.transform.position;
        }, (v2) => master.GetComponent<Rigidbody2D>().MovePosition(v2), vv, afterCast).SetEase(Ease.OutQuint);
        BlinkShow();
        TimerMaster.setInterval(BlinkShow, (int)(afterCast / 10 * 1000), 2);
    }
}
